package Servlet;

import DAO.DAOFactory;
import DAO.MaintenanceDAO;
import DAO.TechnicianDAO;
import javabean.Maintenance;
import javabean.Technician;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/UnassignedMaintance")
public class UnassignedMaintanceServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MaintenanceDAO maintenanceDAO = (MaintenanceDAO) DAOFactory.getMaintenanceDAOInstance();
        TechnicianDAO technicianDAO = (TechnicianDAO) DAOFactory.getTechnicianDAOInstance();
        List<Technician> technicians = null;
        List<Maintenance> maintenances = null;
        try {
            technicians = technicianDAO.getAllTechnicians();
            maintenances = maintenanceDAO.getUnassignedMaintenance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("maintenances",maintenances);
        req.setAttribute("technicians",technicians);
        req.getRequestDispatcher("UnassignedMaintance.jsp").forward(req,resp);
    }
}
